package com.ruoyi.house.controller;

import java.util.List;
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.house.domain.TbHouse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house.domain.TbHouseProperties;
import com.ruoyi.house.service.ITbHousePropertiesService;
import com.ruoyi.house.service.ITbHouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 属性管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/house/properties")
public class TbHousePropertiesController extends BaseController
{
    @Autowired
    private ITbHousePropertiesService tbHousePropertiesService;

    @Autowired
    private ITbHouseService tbHouseService;

    /**
     * 查询属性管理列表
     */
    @PreAuthorize("@ss.hasPermi('house:properties:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbHouseProperties tbHouseProperties)
    {
        startPage();
        List<TbHouseProperties> list = tbHousePropertiesService.selectTbHousePropertiesListWithHouseInfo(tbHouseProperties);
        return getDataTable(list);
    }

    /**
     * 导出属性管理列表
     */
    @PreAuthorize("@ss.hasPermi('house:properties:export')")
    @Log(title = "属性管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbHouseProperties tbHouseProperties)
    {
        List<TbHouseProperties> list = tbHousePropertiesService.selectTbHousePropertiesList(tbHouseProperties);
        ExcelUtil<TbHouseProperties> util = new ExcelUtil<TbHouseProperties>(TbHouseProperties.class);
        util.exportExcel(response, list, "属性管理数据");
    }

    /**
     * 获取属性管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('house:properties:query')")
    @GetMapping(value = "/{houseId}")
    public AjaxResult getInfo(@PathVariable("houseId") Long houseId)
    {
        return success(tbHousePropertiesService.selectTbHousePropertiesByHouseId(houseId));
    }

    /**
     * 新增属性管理
     */
    @PreAuthorize("@ss.hasPermi('house:properties:add')")
    @Log(title = "属性管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbHouseProperties tbHouseProperties)
    {
        return toAjax(tbHousePropertiesService.insertTbHouseProperties(tbHouseProperties));
    }

    /**
     * 修改属性管理
     */
    @PreAuthorize("@ss.hasPermi('house:properties:edit')")
    @Log(title = "属性管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbHouseProperties tbHouseProperties)
    {
        return toAjax(tbHousePropertiesService.updateTbHouseProperties(tbHouseProperties));
    }

    /**
     * 删除属性管理
     */
    @PreAuthorize("@ss.hasPermi('house:properties:remove')")
    @Log(title = "属性管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{houseIds}")
    public AjaxResult remove(@PathVariable Long[] houseIds)
    {
        return toAjax(tbHousePropertiesService.deleteTbHousePropertiesByHouseIds(houseIds));
    }
}
